<template>
    <div class="profitTable">
        <el-form :inline="true" :model="ruleForm" class="demo-form-inline">
            <el-form-item label="报表名称：">
                <el-input placeholder="请输入报表名称" v-model.trim="ruleForm.reportName" maxlength="20"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary"  @click="searchList" id="monitorEnter">查询</el-button>
                <el-button type="primary"  @click="generateReport">生成报表</el-button>
            </el-form-item>
        </el-form>

        <el-table
                :data="tableData"
                class="mt20"
                border
                style="width: 100%">
            <el-table-column type="index" label="序号" width="180" align="center"> </el-table-column>
            <el-table-column prop="reportName" label="报表名称" align="center"></el-table-column>
            <el-table-column prop="baseProfit" :formatter="initCash" align="center" label="利润计提基数（元）"></el-table-column>
            <el-table-column prop="proportionDraw" label="计提比例(%)" align="center">
              <template slot-scope="scope">
                   <el-button type="text"  @click="viewScale(scope.row)">{{scope.row.proportionDraw}}</el-button>
              </template>  
            </el-table-column>
            <el-table-column prop="amountDraw" :formatter="initCash" label="计提金额(元)" align="center"></el-table-column>
            <el-table-column prop="proportionDrawBloc" label="集团管理费计提比例(%)" align="center">
            </el-table-column>
            <el-table-column prop="amountDrawBloc" :formatter="initCash" label="集团管理费(元)" align="center"></el-table-column>
            <el-table-column prop="proportionActual" label="实发占比(%)" align="center"></el-table-column>
            <el-table-column  prop="amountGrantable" :formatter="initCash" label="实发年终奖(元)" align="center"></el-table-column>
            <el-table-column
                    prop="address"
                    label="操作"
                    align="center">
                <template slot-scope="scope">
                    <el-button type="text" @click="awardsinfo(scope.row)">查看</el-button>
                    <el-button type="text" @click="granthander(scope.row)" :disabled="scope.row.isGranted == 1">发放佣金</el-button>
                </template>
            </el-table-column>
        </el-table>

        <div class="pagebar">
          <el-pagination
            background
            layout="total, sizes, prev, pager, next"
            :current-page.sync="ruleForm.pageNum"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="ruleForm.pageSize"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :total="totalSize">
          </el-pagination>
        </div>

        <el-dialog
                title="查看计提比例"
                :visible.sync="dialogVisible"
                width="30%" center>
            <el-table
                    :data="tableData2"
                    border
                    style="width: 100%"
                    v-if="drawType == 1">
                <el-table-column
                         align="center" label="利润区间（万元）" :formatter="initinterval">
                </el-table-column>
                <el-table-column
                        prop="extractProportion"
                        align="center"
                        label="计提点数%">
                </el-table-column>
            </el-table>
            
            <div v-if="drawType == 2" style="text-align: center">
               <div style="border: 1px solid #ccc;padding: 7px">计提点数%</div>
               <div style="border: 1px solid #ccc;border-top: none;padding: 7px">{{extractProportion}}</div>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script type="text/ecmascript-6">
    import api from '@/api/apiPath'
    export default {
        name: 'profitTable',
        title:'利润激励-年',
        data() {
            return {
                ruleForm:{
                    reportName:undefined,
                    pageNum: 0,
                    pageSize: 10,
                },
                totalSize:0,
                tableData: [],
                tableData2:[],
                dialogVisible: false,
                drawType:undefined,//计提方式 1 阶段 2通提
                extractProportion:undefined,//通提的计提点数
            }
        },
        created() {
            this.getlist()
        },
        activated(){
            this.searchList()
        },
        methods: {
            handleCurrentChange(){
                this.getlist()
            },
            handleSizeChange(val){
                this.ruleForm.pageSize = val
                this.getlist();
            },
            initinterval(row, column, cellValue, index){
                let str =''
                if (!row.lower) {
                    str =row.upper + '以下' 
                }else if(row.lower && row.upper){
                    str =  row.lower +'-'+ row.upper
                }else if(!row.upper){
                    str = row.lower +'以上'
                }
                return str
            },
            //佣金发放
            granthander(row){
                this.$confirm('是否发放佣金?', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                }).then(() => {
                    this.axios.post(api.AMOUNTGRANT,{id:row.id}).then((res) => {
                        if (res.data.code == 200) {
                          this.$message({
                              message: '发放成功',
                              type: 'success'
                          });
                         this.getlist()
                        }
                    })

                }).catch(() => {
                  this.$message({
                    type: 'info',
                    message: '已取消'
                  });          
                });
            },
            awardsinfo(row){
                this.$router.push({path:'/profitTableDetail',query:{yearTime:row.timeYear,reportId:row.id}})
            },
            initCash(row, column, cellValue, index){
                if(cellValue !== 0){
                    return cellValue.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",");
                }
                if(cellValue == 0){
                    return "0.00"
                }
            },
            searchList(){
                this.ruleForm.pageNum = 1
                this.getlist()
            },
            getlist(){
                this.axios.post(api.PRODRAWREPORTRESULTS,this.ruleForm).then((res) => {
                    if (res.data.code == 200) {
                        this.tableData = res.data.data.list;
                        this.totalSize = res.data.data.total;
                    }
                })
            },
            //计提比例 查看
            viewScale(row){
                this.tableData2 = []
                this.axios.get(api.SETTLESTARNDINFO+'/'+row.prosettleId).then((res) => {
                        if (res.data.code == 200) {
                            this.dialogVisible = true
                            this.tableData2 = res.data.data.stageContent
                            this.drawType = res.data.data.drawType
                            this.extractProportion = res.data.data.extractProportion
                        }
                })
            },
            generateReport(){
                this.$router.push({path:'/profittableReport'})
            }
        },
        components: {},
        computed: {}
    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="stylus">

</style>
